<template>
  <div>
    <div class="top">
      <el-form :inline="true">
        <el-form-item label="人员搜索：">
          <el-input v-model="data.userName" placeholder="请输入" style="width:180px" />
        </el-form-item>
        <el-form-item label="角色：">
          <el-select v-model="value" clearable style="width: 180px;" placeholder="请选择">
            <el-option
              v-for="item in renyuanList"
              :key="item.roleId"
              :label="item.roleName"
              :value="item.roleId"
            />
          </el-select>
          <el-form-item>
            <el-button type="primary" @click="inquire">
              <i class="el-icon-search" />
              查询</el-button>
          </el-form-item>
        </el-form-item></el-form>
      <svg class="sousuo" />
    </div>
    <div class="list">
      <!-- 列表 -->
      <el-table :data="list">
        <el-table-column type="index" label="序号">
          <template scope="scope">
            <span>{{ (data.pageIndex-1)*data.pageSize+scope.$index+1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="人员名称">
          <template v-slot="{ row }">
            <span>{{ row ?.userName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="角色">
          <template v-slot="{ row }">
            <span>{{ row ?. roleName }}</span>
          </template>

        </el-table-column>
        <el-table-column label="联系电话">
          <template v-slot="{ row }">
            <span>{{ row.mobile }}</span>
          </template>
        </el-table-column>
        <el-table-column label="完成工单(本月)">
          <template v-slot="{ row }">
            <span>{{ row?.workCount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="进行中工单">
          <template v-slot="{ row }">
            <span>{{ row?.progressTotal }}</span>
          </template>
        </el-table-column>
        <el-table-column label="拒绝工单本月">
          <template v-slot="{ row }">
            <span>{{ row?.cancelCount }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="{ row }">
            <el-button type="text" @click="ckxq(row.userId)"><span class="xiugai">查看详情</span> </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-row type="flex" style="height:60px" align="middle" justify="space-between">
        <span class="record">共{{ totalCount }}条记录 第{{ data.pageIndex }}/ {{ totalPage }} 页</span>
        <el-pagination
          :page-size="data.pagesize"
          :current-page="data.pageIndex"
          layout="prev,  next"
          :total="+totalCount"
          prev-text="上一页"
          next-text="下一页"

          @current-change="changePage"
        />
      </el-row>
    </div>
    <el-dialog
      title="新增设备类型"
      :visible.sync="dialogShow"
      width="45%"
      :before-close="handleClose"
    >
      <el-row>
        <el-col :span="7">人员名称:{{ xiangqingList.userName }}</el-col>
        <el-col :span="7">角色:{{ xiangqingList.roleName }}</el-col>
        <el-col :span="7">联系电话:{{ xiangqingList.mobile }}</el-col>
        <el-col :span="7">负责区域:{{ xiangqingList.regionName }}</el-col>
      </el-row>
      <el-row class="xiangbox">
        <el-col class="xiangxx" :span="7" />
        <el-col class="xiangxx" :span="7">总工单数</el-col>
        <el-col class="xiangxx" :span="7">拒绝工单</el-col>
        <el-col class="xiangxx" :span="7">完成工单</el-col>
        <el-col class="xiangxx" :span="7">进行中工单</el-col>
        <el-col class="xiangxx" :span="7">本周</el-col>
        <el-col class="xiangxx" :span="7">{{ week.total }}</el-col>
        <el-col class="xiangxx" :span="7">{{ week.cancelCount }}</el-col>
        <el-col class="xiangxx" :span="7">{{ week.workCount }}</el-col>
        <el-col class="xiangxx" :span="7">{{ week.progressTotal }}</el-col>
        <el-col class="xiangxx" :span="7">本月</el-col>
        <el-col class="xiangxx" :span="7">{{ month.total }}</el-col>
        <el-col class="xiangxx" :span="7">{{ month.cancelCount }}</el-col>
        <el-col class="xiangxx" :span="7">{{ month.workCount }}</el-col>
        <el-col class="xiangxx" :span="7">{{ month.progressTotal }}</el-col>
        <el-col class="xiangxx" :span="7">本年</el-col>
        <el-col class="xiangxx" :span="7">{{ year.total }}</el-col>
        <el-col class="xiangxx" :span="7">{{ year.cancelCount }}</el-col>
        <el-col class="xiangxx" :span="7">{{ year.workCount }}</el-col>
        <el-col class="xiangxx" :span="7">{{ year.progressTotal }}</el-col>
      </el-row>
    </el-dialog>

  </div>
</template>

<script>
import { getgongzu, getrenyaun, getrenyuanxiang, getworkload } from '@/api/role'
import dayjs from 'dayjs'
export default {
  name: 'Role3',
  data() {
    return {
      // 详情列表弹框
      dialogShow: false,
      // 人员判断
      value: '',
      // 获取列表数据
      data: {
        pageIndex: 1,
        pageSize: 10,
        userName: '',
        roleId: '',
        isRepair: ''
      },
      // 总数据
      totalCount: '',
      // 总页数
      totalPage: '',
      // 列表数据
      list: [],
      pointLocation: {
        pageIndex: 1,
        pageSize: 10000000
      },
      // 售货机状态映射表
      vmStatuslist: {
        0: '未投放',
        1: '运营',
        3: '撤机'
      },
      // 人员列表
      renyuanList: [],
      Body: {
        userName: '',
        roleId: '',
        mobile: '',
        regionId: '',
        regionName: '',
        status: false,
        image: ''
      },
      // 人员详情
      xiangqingList: [],
      // 工单数据传值
      weekLisr: {
        userId: '',
        start: dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD HH:mm:ss'), // 开始
        end: dayjs().format('YYYY-MM-DD HH:mm:ss') // 结束
      },
      monthLisr: {
        userId: '',
        start: dayjs().startOf('month').format('YYYY-MM-DD HH:mm:ss'), // 开始
        end: dayjs().format('YYYY-MM-DD HH:mm:ss') // 结束
      },
      yearLisr: {
        userId: '',
        start: dayjs().startOf('year').format('YYYY-MM-DD HH:mm:ss'), // 开始
        end: dayjs().format('YYYY-MM-DD HH:mm:ss')// 结束
      },
      week: [],
      month: [],
      year: []
    }
  },
  created() {
    // 页面列表
    this.getEquipmentList()
    this.getrenyuanxinxi()
  },
  methods: {
    // 关闭弹窗
    handleClose() {
      this.dialogShow = false
    },
    // 分页
    changePage(newPage) {
      // console.log(newPage)
      this.data.pageIndex = newPage
      // console.log(this.data)
      this.getEquipmentList()
    },
    // 获取列表数据
    async getEquipmentList() {
      if (this.value === 2) {
        this.data.isRepair = false
      } else if (this.value === 3) {
        this.data.isRepair = true
      } else {
        this.data.isRepair = ''
      }

      console.log(this.data)
      const res = await getworkload(this.data)
      this.list = res.currentPageRecords
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      console.log(this.list)
    },
    // 查询重新渲染页面
    inquire() {
      this.getEquipmentList()
    },
    // 查看详情
    async ckxq(id) {
      this.xiangqingList = await getrenyuanxiang(id)
      this.weekLisr.userId = id
      this.monthLisr.userId = id
      this.yearLisr.userId = id
      this.week = await getgongzu(this.weekLisr)
      this.month = await getgongzu(this.monthLisr)
      this.year = await getgongzu(this.yearLisr)
      console.log(this.week)
      console.log(this.month)
      console.log(this.year)

      this.dialogShow = true
    },
    async getrenyuanxinxi() {
      this.renyuanList = await getrenyaun()
      console.log(this.renyuanList)
    }

  }
}
</script>

<style  lang='scss' scoped>
.selected{
position: relative;
    width: 134px;
    height: 134px;
    padding-top: 16px;
    background-color: #f6f7fb;
    -webkit-box-shadow: 0 2px 4px 0 rgba(0,0,0,.06);
    box-shadow: 0 2px 4px 0 rgba(0,0,0,.06);
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
}
 .top{
    height: 80px;
    margin: 20px;
    padding: 18px;
    background-color: #fff;
  }
    .list{
    padding: 18px;
    margin: 20px;
    background-color: #fff;
   }
    ::v-deep.el-pagination .btn-next{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
   margin: 10px;
}

::v-deep.el-pagination .btn-prev{
  background-color: #d5ddf8 !important;
  width: 70px;
  height: 30px;
  text-align: center;
  border-radius: 3px;
  margin: 10px;
}
.record{
  color: #dbdfe5;
}
.xiugai{
  color: #6eabfe;
}
.sahnchu{
  color: #fb9782;
}
.rowimg{
      display: block;
    width: 24px;
    height: 24px;
    -o-object-fit: cover;
    object-fit: cover;
    border-radius: 50%;
    background: #f3f6fb;
    border: 1px solid #f3f6fb;
}
  .avatar-uploader .el-upload {
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    border: 2px dashed  #b7b7b7 !important;
    font-size: 28px;
    color: #8c939d;
    background-color: #f3f6fb;
    width: 100px;
    height:100px;
    line-height: 100px;
    text-align: center;
  }
  .avatar {
    // border: 2px dashed  #000 !important;
    width: 100px;
    height:100px;
    display: block;
  }
  .dialogboxfood{
    width: 70%;
    display: flex;
    justify-content: center;
    .footBtn{
      margin-left: 60 px;
    }
  }
  .el-row {
    margin-bottom: 20px;
    padding: 20px;
    background-color: #f3f6fb;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    border-radius: 4px;
    margin-top: 5px;
    margin-bottom: 5px;
  }
.xiangbox{
  display: flex;
  justify-content: center;
  width: 100%;
 flex-wrap: wrap;
  .xiangxx{
    border: 1px solid #d8dde3;
    width: 20%;
    text-align: center;
    padding: 10px 0;
    margin: 0;
    border-radius: 0;
  }
}
</style>
